package com.bishe.demo.modules.tourism.service.impl;

import com.bishe.demo.modules.account.dao.UserDao;
import com.bishe.demo.modules.account.dao.UserRoleDao;
import com.bishe.demo.modules.account.entity.User;
import com.bishe.demo.modules.account.entity.UserRole;
import com.bishe.demo.modules.common.entity.ResultEntity;
import com.bishe.demo.modules.tourism.dao.RouteDao;
import com.bishe.demo.modules.tourism.dao.SupplierDao;
import com.bishe.demo.modules.tourism.entity.Supplier;
import com.bishe.demo.modules.tourism.service.SupplierService;
import com.bishe.demo.util.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.beans.Transient;

/**
 * @Description SupplierServiceImpl
 * @Author Lubb
 * @Date 2021/3/29 15:28
 */
@Service
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    private UserDao userDao;
    @Autowired
    private UserRoleDao userRoleDao;

    @Override
    @Transient
    public ResultEntity<User> addSupplier(User user) {
        User u = userDao.getUserByUserName(user.getUserName());
        if (u == null) {
            user.setPassword(MD5Util.getMD5(user.getUserName(), user.getPassword()));
            userDao.insertUser(user);
            userRoleDao.insertUserRole(new UserRole(user.getUserId(), 5));
            return new ResultEntity<User>(ResultEntity.ResultStatus.SUCCESS.code, "注册成功", user);
        }
        return new ResultEntity<User>(ResultEntity.ResultStatus.FAILED.code, "账号已存在");

    }
}
